﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Adapters;
using System.Data;
using BL;
using BE;


namespace UI.Secretaria
{
    public partial class frmlicencias : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                Llena_combos();
                llenaGrilla();
                if (User.Identity.Name.Equals("mvillaseca", StringComparison.OrdinalIgnoreCase))
                {
                    BtnNnuevo.Visible = false;
                    BtnNnuevo.Enabled = false;

                }
            }

        }



        protected void TxtInicio_TextChanged(object sender, EventArgs e)
        {

        }

        protected void TxtSalida_TextChanged(object sender, EventArgs e)
        {

        }

        protected void BtnExportar_Click(object sender, ImageClickEventArgs e)
        {
            this.Gridrequerimientos.Columns[7].Visible = false;
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=Registrodelicencias.xls");
            Response.ContentType = "application/vnd.xlsx";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            Gridrequerimientos.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();
            this.Gridrequerimientos.Columns[7].Visible = true;
        }



        void llenaGrilla()
        {


            string filtro1,filtro2, filtro3, filtro4,filtro5;

            if (Ddl_Semestre.SelectedItem.Text == "TODOS")
                filtro1 = "TODOS";
            else filtro1 = Ddl_Semestre.SelectedItem.Text;
            
            if (TxtCodigo.Text.Trim().Length == 0)
                filtro2 = "TODOS";
            else filtro2 = TxtCodigo.Text;

           

            if (TxtDesc.Text.Trim().Length==0)
                filtro4 = "TODOS";
            else filtro4 = TxtDesc.Text;

            if (ddlTipo.SelectedItem.Text == "TODOS")
                filtro5 = "TODOS";
            else filtro5 = ddlTipo.SelectedValue;


            Secretaria_BL obj = new Secretaria_BL();
            DataTable dato = new DataTable();


            dato = obj.DATA_OBS_Listar(filtro1, filtro2, "", filtro4, filtro5);
            Gridrequerimientos.DataSource = dato;
            Gridrequerimientos.DataBind();

            this.Gridrequerimientos.Columns[7].Visible = false;



        }

        protected void btnBuscar_Click(object sender, EventArgs e)
        {
            llenaGrilla();
        }

        protected void BtnNnuevo_Click(object sender, EventArgs e)
        {
            Response.Redirect("frmIngresoLicencia.aspx");
        }





        protected void Gridrequerimientos_PageIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Gridrequerimientos_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {

        }

        protected void Gridrequerimientos_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            Gridrequerimientos.PageIndex = e.NewPageIndex;
            Gridrequerimientos.DataBind();
            llenaGrilla();
        }

        protected void Gridrequerimientos_SelectedIndexChanged(object sender, EventArgs e)
        {
            string var0, var1, var2, var3, var4, var5, var6, var7;
            var0 = Gridrequerimientos.SelectedRow.Cells[0].Text; //semestre
            var1 = Gridrequerimientos.SelectedRow.Cells[1].Text; //codigo
            var2 = Gridrequerimientos.SelectedRow.Cells[2].Text; //nombre
            var3 = Gridrequerimientos.SelectedRow.Cells[3].Text; //condicion
            var4 = Gridrequerimientos.SelectedRow.Cells[4].Text; //estado
            var5 = Gridrequerimientos.SelectedRow.Cells[5].Text; //descripcion
            var6 = Gridrequerimientos.SelectedRow.Cells[6].Text;  //observaciones
            var7 = Gridrequerimientos.SelectedRow.Cells[7].Text;  //revision 
            Lbl_Id.Text = var0;
            lbl_nombre.Text = var2;
            TxtEstado2.Text = var4;
            TxtDesc2.Enabled = false;
            TxtDesc2.Text = var5;
            //TxtFechaSal.Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
            //AuxSalida = DateTime.Now;
            txtObservaciones.Text = var7;
            //llenaGrilla();
            mdArticulos.Show();
            

            //if (id_estado == "Pendiente")
            //{


            //}
            //else
            //{
            //    MessageBox("El requerimiento seleccionado ya no se puede se anulado");
            //}
        }


        protected void MessageBox(string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                Response.Write("<script type=\"text/javascript\" language=\"javascript\">");
                Response.Write("alert('" + message + "');");
                Response.Write("</script>");
            }
        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            mdArticulos.Hide();
        }

        protected void TxtFechaSal_TextChanged(object sender, EventArgs e)
        {

        }

        protected void txtObservaciones_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Llena_combos()
        {

            DataTable dato = new DataTable();
            Alumno_BL obj = new Alumno_BL();


            dato = obj.DATA_PERIODO_listaxSemestre("TODOS");
            Ddl_Semestre.DataSource = dato;
            Ddl_Semestre.DataTextField = "semestre";
            Ddl_Semestre.DataValueField = "Id_periodo";
            Ddl_Semestre.DataBind();

            Ddl_Semestre.Items.Insert(0, "TODOS");

        }







 
    }
}